<!DOCTYPE html>
<html>
<head>
    <title><%=title%></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="stylesheets/public.css">
    <link rel="stylesheet" href="stylesheets/bootstrap.min.css">
    <script src="javascripts/jquery-1.7.1.min.js"></script>
    <script src="javascripts/bootstrap.min.js"></script>

    <script>
        $(function(){
            $('#username').focus();
        });
        function checkUserInfo(){
            var uname = $('#username').val();
            var password = $('#password').val();
            var password1 = $('#password1').val();
            var phone = $.trim($('#phone').val());
            var email = $.trim($('#email').val());

            var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            var mobile = /^0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/;

            if(uname==""){
                alert("用户名不能为空！");
            }else if(password==""){
                alert("密码不能为空");
            }else if(password != password1){
                alert("输入的两次密码不一致");
            }else if(!mobile.test(phone)){
                alert("手机号码格式不对");
            }else if(!reg.test(email)){
                alert("请输入正确的邮箱格式");
            }
            else{
                $.post('/validateUser',{username:uname},function(data){
                    if(data === "[]"){
                        $('#reg_form').submit();
                    }else{
                        alert("该用户名已存在");
                    }
                });
            }
        }

        function reset(){
            $('#reg_form').eq(0)[0].reset();
        }

    </script>
</head>
<body>
<div class="main pagecenter round">
    <div class="page-header">
        <h1 class="h1">注册</h1>
    </div>
    <form id="reg_form" action="/executeRegister" method="post">
        <div class="input-group input_size">
            <span class="input-group-addon">用&nbsp;&nbsp;户&nbsp;&nbsp;名</span>
            <input id="username" name="uname" type="text" class="form-control" placeholder="Username">
        </div>
        <div class="input-group input_size input_margintop">
            <span class="input-group-addon">输入密码 </span>
            <input id="password" name="password" type="password" class="form-control" placeholder="Password">
        </div>
        <div class="input-group input_size input_margintop">
            <span class="input-group-addon">确认密码 </span>
            <input id="password1" type="password" class="form-control" placeholder="Password">
        </div>
        <div class="input-group input_size input_margintop">
            <span class="input-group-addon">手机号码 </span>
            <input id="phone" name="phone" type="text" class="form-control" placeholder="手机号">
        </div>
        <div class="input-group input_size input_margintop">
            <span class="input-group-addon">邮箱账号 </span>
            <input id="email" name="email" type="text" class="form-control" placeholder="Email" style="margin-left: 0px">
        </div>
        <br><br><br>
        <p>
            <a id="reg_btn" href="javascript:void(0);" class="btn btn-primary login_btn" role="button" onclick="checkUserInfo();">注册</a>
            <a id="reset" href="javascript:void(0);" class="btn btn-default reg_btn" role="button" onclick="reset();">重置</a>
        </p>

    </form>
</div>

</body>
</html>